﻿@using static Bit.Core.Utilities.CoreHelpers;

@inject SignInManager<Bit.Core.Models.Table.User> SignInManager
@inject Bit.Core.Services.II18nService i18nService
@inject Bit.Portal.EnterprisePortalCurrentContext EnterprisePortalCurrentContext

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Business Portal</title>

    <link rel="stylesheet" href="~/css/webfonts.css" />
    <environment include="Development">
        <link rel="stylesheet" href="~/lib/font-awesome/css/font-awesome.css" />
        <link rel="stylesheet" href="~/css/site.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/lib/font-awesome/css/font-awesome.min.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
    </environment>
</head>
<body>
    <nav class="navbar navbar-expand-md navbar-dark bg-primary mb-4">
        <div class="container">
            <a class="navbar-brand" asp-controller="Home" asp-action="Index">
                <i class="fa fa-shield" aria-hidden="true"></i>
            </a>
            @if (SignInManager.IsSignedIn(User))
            {
                <div class="collapse navbar-collapse" id="navbarCollapse">
                    <ul class="navbar-nav mr-auto">
                        @if (EnterprisePortalCurrentContext.SelectedOrganizationDetails.UseSso &&
                           EnterprisePortalCurrentContext.AdminForSelectedOrganization)
                        {
                            <li class="nav-item">
                                <a class="nav-link" asp-area="" asp-controller="Sso" asp-action="Index">
                                    @i18nService.T("SingleSignOn")
                                </a>
                            </li>
                        }

                        @if (EnterprisePortalCurrentContext.SelectedOrganizationDetails.UsePolicies &&
                           EnterprisePortalCurrentContext.AdminForSelectedOrganization)
                        {
                            <li class="nav-item">
                                <a class="nav-link" asp-area="" asp-controller="Policies" asp-action="Index">
                                    @i18nService.T("Policies")
                                </a>
                            </li>
                        }
                    </ul>
                </div>
            }
            @if (SignInManager.IsSignedIn(User))
            {
                @await Component.InvokeAsync("OrganizationPicker")
                <ul class="navbar-nav flex-row ml-md-auto d-none d-md-flex">
                    <li class="nav-item dropdown">
                        <a class="nav-item nav-link dropdown-toggle" href="#" id="nav-profile" data-toggle="dropdown"
                           aria-haspopup="true" aria-expanded="false">
                            <i class="fa fa-user-circle fa-lg" aria-hidden="true"></i>
                        </a>
                        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav-profile">
                            <div class="dropdown-item-text d-flex align-items-center">
                                <i aria-hidden="true" class="fa fa-user-circle fa-lg"></i>
                                <div class="ml-2 overflow-hidden">
                                    <span>Logged in as</span>
                                    <small class="text-muted">@User.Identity.Name</small>
                                </div>
                            </div>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">
                                <i class="fa fa-fw fa-share fa-flip-horizontal" aria-hidden="true"></i>
                                Return to My Vault
                            </a>
                            <form asp-controller="Auth" asp-action="Logout" method="post">
                                <button type="submit" class="dropdown-item">
                                    <i class="fa fa-fw fa-sign-out" aria-hidden="true"></i>
                                    Log Out
                                </button>
                            </form>
                        </div>
                    </li>
                </ul>
            }
        </div>
    </nav>

    <div class="container page-content">
        @RenderBody()
    </div>

    <div class="container footer text-muted">
        <div class="row">
            <div class="col">
                &copy; @DateTime.Now.Year, Bitwarden Inc.
            </div>
            <div class="col text-center"></div>
            <div class="col text-right">
                Version @GetVersion()
            </div>
        </div>
    </div>

    <environment include="Development">
        <script src="~/lib/jquery/jquery.slim.js"></script>
        <script src="~/lib/popper/popper.js"></script>
        <script src="~/lib/bootstrap/js/bootstrap.js"></script>
    </environment>
    <environment exclude="Development">
        <script src="~/lib/jquery/jquery.slim.min.js" asp-append-version="true"></script>
        <script src="~/lib/popper/popper.min.js" asp-append-version="true"></script>
        <script src="~/lib/bootstrap/js/bootstrap.min.js" asp-append-version="true"></script>
    </environment>

    <script src="~/js/site.js" asp-append-version="true"></script>
    @RenderSection("Scripts", required: false)
</body>
</html>
